#include "pressure.h"
#include "delay.h"

uint16_t BSP_PressureSensor_ReadData(Device_PressureSensor *dv){
    uint16_t adcData = 0U;
    ADC_RegularChannelConfig(dv->adcPort, dv->adcChannel, 1, ADC_SampleTime_480Cycles);
    ADC_SoftwareStartConv(dv->adcPort);
    while(!ADC_GetFlagStatus(dv->adcPort, ADC_FLAG_EOC));
    adcData = ADC_GetConversionValue(dv->adcPort);
    return adcData;
}

uint16_t BSP_PressureSensor_SampleAndReadData(Device_PressureSensor *dv, uint16_t samplingTime){
    uint16_t t;
    uint32_t r = 0U;
    for(t = 0; t < samplingTime; t++){
        r += BSP_PressureSensor_ReadData(dv);
        BSP_DelayMs(5);
    }
    r /= samplingTime;
    return r;
}
